<?php 
    require_once ("Includes/simplecms-config.php"); 
    require_once  ("Includes/connectDB.php");
    require_once ("Functions/printscores.php");
    include("Includes/header.php");  
    
    ini_set('display_errors',1); 
    error_reporting(E_ALL);       
?>
    <div id="main">
    <?php
        $swimid = $_GET['swimid'];
        $query = 'SELECT nickname, team_id FROM swimmers WHERE id = ? LIMIT 1';
        $statement = $databaseConnection->prepare($query);
        $statement->bind_param('s', $swimid);
        $statement->execute();

        if ($statement->error){
            die('Database query failed: ' . $statement->error);
        }

        $statement->store_result();
        $statement->bind_result($nickname, $teamid);
        $statement->fetch();

        if ($statement->num_rows == 0 || $teamid != 1) {
            echo '<div class="error">Error: SwimID '.$swimid.' not found</div>';
        }
        else {
    ?>
    <h3><?php echo $nickname;?>:</h3>      
        <?php printScoresBySwimmer($swimid, $databaseConnection);
        } ?>
    </div>
</div> <!-- End of outer-wrapper which opens in header.php -->

<?php 
    include ("Includes/footer.php");
?>